package com.bit.demin;

public class Student {
    private String name;
    private int age;
    public static String classRoom;//

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }
    //实例代码块
    {
        this.name = "vvv";
        this.age = 20;
        System.out.println("实例代码块");
    }
    //静态代码块
    static{
        classRoom = "109";
        System.out.println("静态代码块");
    }
    public void eat(){
        System.out.println(name+"正在吃饭");
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public static void main(String[] args) {
        //eat();//err  静态方法中不能直接调用非静态方法  可以通过对象的引用调用
        Student student1 = new Student("a", 15);
        Student student2 = new Student("b", 16);
        Student student3 = new Student("c", 17);
        System.out.println(student3);//重写toString方法就可以打印student3这个引用所指向对象里的内容
        Student.classRoom = "109";//静态的属性用类名.xxx进行访问 不依赖于对象
    }
}

class Test{

    public static void main(String[] args) {
        Student.classRoom = "109";
    }
}